package njClass.mvc.core
{	
	import flash.events.Event;
	import flash.events.EventDispatcher;

	public class facade extends EventDispatcher
	{
		private static var dispatcher:Object=new Object();
		private static var app:facade;
		
		public function facade(_target:Object){
			dispatcher=_target;
		}
		
		public static function getInstance(_target:Object=null):facade{
			if(app==null&&_target!=null){
				app=new facade(_target);
			}
			return app;
		}
		
		public static function get App():Object{
			return dispatcher;
		}
		
		public function sendEvent(EventName:String,Target:Object=null):void{
			if(Target!=null){
				Target.dispatchEvent(new Event(EventName));
			}else{
				dispatcher.dispatchEvent(new Event(EventName));
			}
		}
		
		public function initEvent(EventName:String,CommandName:Command,Target:Object=null):void{
			if(Target!=null){
				Target.addEventListener(EventName,regCommand);
			}else{
				dispatcher.addEventListener(EventName,regCommand);
			}
			
			function regCommand(evt:Event):void{
				CommandName.StartUp();
			}
		}
	}
}